package Jump;

import java.awt.*;
import java.util.Random;

public class Cloud {
    public int x;
    public int y;
    public int width;
    public int speed;
    public static final Random random = new Random();

    public Cloud() {
        this.x = JumpPanel.WIDTH + random.nextInt(100);
        this.y = 30 + random.nextInt(100);
        this.width = 40 + random.nextInt(40);
        this.speed = 1 + random.nextInt(2);
    }
    //云朵动画
    public void update() {
        x -= speed;
        //出界循环至右侧
        if (x + width < 0) {
            x = JumpPanel.WIDTH + random.nextInt(100);
            y = 80 + random.nextInt(100);
        }
    }
    //绘制云朵
    public void draw(Graphics g) {
        g.setColor(new Color(244, 244, 244));
        g.fillOval(x, y, width, width / 2);
        g.fillOval(x + width / 4, y - width / 8, width / 2, width / 3);
        g.fillOval(x + width / 2, y, width / 2, width / 3);
    }
}
